angular.module('mall-info', ['head-toast'])

.controller 'MallInfoCtrl', ($scope, $state, $http, $ionicHistory, userData, $ionicPopup,mallInfo,showToast) ->
    _.extend $scope,
        user:
            sitename: undefined
            firsturl: undefined

        goBack: ->
            $ionicHistory.goBack()

        goSave: ->
            $http.post('/utf-8data/', {
                        action: 'editshop',
                        userid: userData.getToken(),
                        sitename: $scope.user.sitename,
                        siteurl: $scope.user.firsturl,
                    }
            )
            .success (resp) ->
                if resp?.status == '0'
                    showToast '保存成功'
                    $ionicHistory.goBack()
                else
                    showToast resp.msg
            .error ->
                showToast '您的网络又调皮了'
        clear: (i) ->
            if i == '1'
                $scope.user.sitename = ''
            else if i == '2'
                $scope.user.firsturl = ''

    $scope.user = mallInfo.mall


